<template>
    <div>
        <el-form :model="form" :rules="rules" ref="form">
            <el-form-item label="系名" label-width="60px" prop="name">
                <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item style=" display: flex; justify-content: flex-end;">
                <el-button type="primary" @click="submit" @keydown.enter="submit" tabindex="0"
                    ref="actionBtn">确定</el-button>
                <el-button @click="qx">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { departmentadd } from '@/api/department';
export default {
    data() {
        return {
            form: {
                id: -1,
                name: ""

            },
            rules: {
                name: [{
                    required: true, message: "请输入系名", trigger: "blur"
                }]
            }

        }
    },
    methods: {
        submit() {
            // 触发表单验证
            this.$refs['form'].validate(falg => {
                if (falg) {
                    departmentadd(this.form).then(res => {
                        if (res.code === 0) {
                            this.$message({
                                type: "success",
                                message: "添加成功"
                            })
                            // 通知父级关闭对话框
                            this.$emit("close")
                        }

                    })
                }
            })


        },
        submit1() {
            his.$refs['form'].validate(falg => {
                if (falg) {
                    departmentadd(this.form).then(res => {
                        if (res.code === 0) {
                            this.$message({
                                type: "success",
                                message: "添加成功"
                            })
                            // 通知父级关闭对话框
                            this.$emit("close")
                        }

                    })
                }
            })
        },
        qx() {
            this.$emit("close")
        }
    },
    mounted() {
        this.$refs.actionBtn.$el.focus();
    }
}
</script>

<style lang="sass" scoped>

</style>